<?php


namespace App\Models\CacheModel\live;


use App\Models\Api\BaseCache;

class LiveGift extends BaseCache
{
    protected $table = 'wechat_backup_07_18_14_43_00.live_gift';

    protected $cacheModel = 'live.gift';

    public function getInfoByIdsInData($ids, $type, $sortType)
    {
        try
        {
            if ($ids)
            {
                $where = ['id' => ['in', $ids]];
            } else
            {
                if ($type[1])
                {
                    $where = ['status' => 1, 'type' => $type[1]];
                } else
                {
                    $where = ['status' => 1];
                }
            }
            $data = $this
                ->where($where)
                ->order('sort ', $sortType)
                ->column('name,img,coin,type,is_lottie,lottie,status,hot,contribution,sort,create_time', 'id');
        }
        catch (\Exception $e)
        {
            $data = [];
        }

        return $data;
    }

    /**
     * 获取动图文件
     * @return array
     * @throws \Exception
     */
    public function getLottieFile()
    {
        $giftList = (new LiveGift())->getListPage('', 'sort', [], 0);

        $lottieFile = [];
        foreach ($giftList['data'] as $datum)
        {
            if ($datum['is_lottie'] == 1)
            {
                $lottieFile[] = json_decode($datum['lottie'], true)['url'];
            }
        }

        return array_filter($lottieFile);
    }
}
